/*
 * @Author: evan.wan
 * @Date:   2016-06-25 15:55:20
 */

'use strict';
define([
    '../../common/service',
    'sutable'
], function(
    http
) {
    function me() {
        var self = this;
        this.init = function() {
            self.$root = $('.fmp-container');
            self.tableTh = [
                {label:"day",isShow:true},
                {label:"week",isShow:true},
                {label:"campaignId",isShow:false},
                {label:"campaignName",isShow:false},
                {label:"adSetId",isShow:false},
                {label:"adSetName",isShow:false},
                {label:"adId",isShow:false},
                {label:"adName",isShow:false},
                {label:"productId",isShow:false},
                {label:"optimizationGoal",isShow:false},
                {label:"billingEvent",isShow:false},
                {label:"country",isShow:false},
                {label:"gender",isShow:false},
                {label:"age",isShow:false},
                {label:"device",isShow:false},
                {label:"placement",isShow:false},
                {label:"account",isShow:false},
                {label:"autoBid",isShow:false},
                {label:"adType",isShow:false},
                {label:"spend",isShow:true},
                {label:"fbData-impressions",isShow:true},
                {label:"fbData-clicks",isShow:true},
                {label:"fbData-cpc",isShow:true},
                {label:"fbData-cart",isShow:true},
                {label:"fbData-checkout",isShow:true},
                {label:"fbData-checkoutCR",isShow:true},
                {label:"fbData-cps",isShow:true},
                {label:"fbData-salesAmount",isShow:true},
                {label:"fbData-roi",isShow:true},
                {label:"gaData-clicks",isShow:true},
                {label:"gaData-cpc",isShow:true},
                {label:"gaData-cart",isShow:true},
                {label:"gaData-cartCR",isShow:true},
                {label:"gaData-pays",isShow:true},
                {label:"gaData-cr",isShow:true},
                {label:"gaData-cpa",isShow:true},
                {label:"gaData-orderAmount",isShow:true},
                {label:"gaData-orderPrice",isShow:true},
                {label:"gaData-roi",isShow:true}
            ];
            self.pageNav = {
                tPage: 1,
                cPage: 1,
                pSize: 20,
                tSize: 1
            };
            self.menus = [];
            self.param = {
                "groups": ["day"],       // 分组条件，指定需要根据什么进行分组，取值范围请参考支持字段列表（必须项，且day和webSite必须进行分组）
                "filters": {
                    "day": {
                        "since": moment().add("day", -1).format("YYYY-MM-DD"),
                        "until": moment().format("YYYY-MM-DD")
                    },
                    "webSite": [],
                    "age": [],
                    "gender": [],
                    "device": [],
                    "account": [],
                    "adType": [],
                    "adId": [],
                    "adName": []
                },                  // 过滤条件（必须项，且day和webSite必须进行过滤），除了day以外，别的均以数组形式传递，名称和groups字段取值一致，但是ad/asSet/campaign需要拆分为
                                    // adId/adName/adSetId/adSetName/campaignId/campaignName，因为需要支持id和name检索
                "pSize": self.pageNav.pSize,        // 分页大小（必须项，正整数）
                "cPage": self.pageNav.cPage           // 请求第几页（必须项，从1开始）
            };
            self.render();
        }

        this.render = function() {

            self.event();
        }

        this.event = function() {

            self.reqMenus();

            //绑定表头配置
            self.bindConfigEvent();

            //绑定查询
            self.$root.find('#btnSearch').off('click').on('click', $.proxy(self.bindSearch, self));

            //绑定导出
            self.$root.find('#btnExport').off('click').on('click', $.proxy(self.bindExport, self));


            //modal打开先请求元素数据
            //self.$root.find('#add-template-btn').off('click').on('click', $.proxy(self.openUploadDialog, self));
            //self.$root.find('.div-filter').off('click').on('click', $.proxy(self.initFilter, self));
            //SimpleElement.init(self.templateId, function() {
            //    console.log(1);
            //});
            //BrandLogo.init(self.templateId, function() {
            //    console.log(2);
            //});
            //FontAndDesignElement.init(self.templateId, self.templateName, self.templateImg, function() {
            //    console.log(3);
            //});

        }

        this.reqMenus = function() {
            http.work("/ec/allWebSite", null, "GET").then(function(res){
                if(res.succeed) {
                    console.log(res)
                    self.menus = res.data;
                    //初始化条件
                    self.initCondition();
                } else {
                    self.alert("error");
                }
            });
        }

        /**
         * table实体数据
         */
        this.reqData = function(p) {
            if (_.isEmpty(p.filters.webSite)) {
                self.alert(I18N.getText('ecReport','requireWebSite'));
                return false;
            }
            var loadingArea = $('.data-container');
            Kit.loading.show(loadingArea);

            //参数中list去重
            p.groups = _.uniq(p.groups);
            _.map(p.filters, function (i) {
                if (_.isArray(i)) {
                    return _.uniq(i);
                } else {
                    return i;
                }
            });
            http.work("/ec/report", p, "POST").then(function(result){
                if(result.succeed) {
                    if (result.data.list && result.data.fbSummary) {
                        var totalCnt = result.data.fbSummary.count;
                        self.pageNav.tSize = totalCnt;
                        self.pageNav.tPage = parseInt(self.pageNav.tSize / self.pageNav.pSize);
                        if (self.pageNav.tSize % self.pageNav.pSize > 0) {
                            self.pageNav.tPage = self.pageNav.tPage + 1;
                        }
                        self.$root.find('.table-page .page-left-total span').text(totalCnt);
                        self.$root.find('.table-page .page-left-total').removeClass('hidden');
                        $("div.ndp-page-wrapper[name=drop-page2]").empty().page({
                            type:3,//1 普通，2 带显示条数，3，简洁紧凑格式的菜单
                            totalItems:totalCnt,//总共有n条数据
                            perPage:self.pageNav.pSize,//每页默认显示10条
                            currentPage:  self.pageNav.cPage,
                            perPages: [10, 20, 50]
                        }).off("PAGE_CHANGE").on("PAGE_CHANGE", function(e) { //页数点击 事件
                            console.log(e.originalEvent.data); //{currentPage: 第几页 int} currentPage: 1
                            self.pageNav.cPage = e.originalEvent.data.currentPage;
                        }).off("SHOW_ITEMS_CHANGE").on("SHOW_ITEMS_CHANGE", function(e) { //页数点击 事件
                            console.log(e.originalEvent.data); //{currentPage: 第几页 int}  {currentPage: 1, perpage: 50}
                            self.pageNav.cPage = e.originalEvent.data.currentPage;
                            self.pageNav.pSize = e.originalEvent.data.perpage;
                        });
                        //初始化表格
                        self.initTable(result.data);
                    } else {
                        self.alert(I18N.getText('ecReport','noData'));
                    }
                } else {
                    self.alert("error");
                }
                Kit.loading.hide(loadingArea);
            });
        }

        this.bindSearch = function() {
            self.param.cPage = 1;
            self.pageNav.cPage = 1;
            self.reqData(self.param);
        }

        this.bindExport = function() {
            self.param.cPage = 1;
            self.pageNav.cPage = 1;
            var p = self.param;
            if (_.isEmpty(p.filters.webSite)) {
                self.alert(I18N.getText('ecReport','requireWebSite'));
                return false;
            }

            //参数中list去重
            p.groups = _.uniq(p.groups);
            _.map(p.filters, function (i) {
                if (_.isArray(i)) {
                    return _.uniq(i);
                } else {
                    return i;
                }
            });
            var _thCache = new Array();
            //var thList = $('#ecReportTable thead[class!="set-top"] th');
            //var $v;
            //$.each( thList, function( i, v ){
            //    $v = $(v);
            //    var $tempDom =$('.config-area li[th-name="'+ v.getAttribute('th-name') +'"]', $('#ecReportTable').parents('.table-warp').eq(0));
            //    if($tempDom[0]){
            //        if($tempDom.find( 'input[type="checkbox"]')[0]){
            //            if($tempDom.find( 'input[type="checkbox"]').get(0).checked)
            //                _thCache.push(v.getAttribute('th-name'));
            //        }
            //    }
            //});
            //p.ths = _thCache;
            window.open(apiUrl + '/ecReport/export?param=' + JSON.stringify(p));
        }

        /**
         * table表头配置
         */
        this.bindConfigEvent = function(){
            var _this = this;
            //打开/关闭设置区域
            var tableWarp = $('.ndp-sutable-wrapper');
            var configAction = $( '.config-action');
            configAction.unbind( 'click' );
            configAction.bind( 'click', function(){
                var _configAction = $( this ),		//展示事件源
                    _configArea = _configAction.parents('.config-area').eq(0),	//设置区域
                    _configList = $( '.config-list',_configArea );//设置列表
                //关闭
                if( _configList.css( 'display' ) == 'block' ){
                    _configList.animate( {
                        width: '0px'
                    }, _this.animateTime, function(){
                        _configList.hide();
                    } );
                    return false;
                }
                //打开
                var _tableWarp = _configAction.parents( '.table-warp' ).eq( 0 ),//当前事件源所在的div
                    _table	= $( '[list-manager]', _tableWarp ),				//对应的table
                    _thList = $( 'thead th', _table ),							//所有的th
                    _trList = $( 'tbody tr', _table ),							//tbody下的tr
                    _td;														//与单个th对应的td
                $.each( _thList, function( i, v ){
                    v = $( v );
                    $.each( _trList, function( i2, v2 ){
                        _td = $( 'td', v2 ).eq( v.index() );
                        _td.css( 'display', v.css( 'display' ) );
                    } );
                } );
                //验证当前是否只有一列处于显示状态 并根据结果进行设置是否可以取消显示
                var checkedLi = $('.checked-li', _configArea);
                checkedLi.length == 1 ? checkedLi.addClass('no-click') : checkedLi.removeClass('no-click');

                _configList.css( 'width','auto' );
                _configList.fadeIn( _this.animateTime );
            } );
            //鼠标离开列表区域事件
            tableWarp.unbind( 'mouseleave' );
            tableWarp.bind( 'mouseleave', function(){
                var _configList = $( '.config-list', this );//设置列表
                _configList.width(0)
                _configList.hide();
            });
            //设置事件
            $( '.config-list li').unbind( 'click' );
            $( '.config-list li').bind( 'click', function(){
                var _only = $( this ),		//单个的设置项
                    _configArea 	= _only.parents( '.config-area' ).eq( 0 ),			//事件源所在的区域
                    _thName 		= _only.attr( 'th-name' ),							//单个设置项的thName
                    _checkbox 		= _only.find( 'input[type="checkbox"]' ),			//事件下的checkbox
                    _checkedList;		//当前处于选中状态的展示项
                if( _only.hasClass( 'no-click' ) ){
                    return false;
                }
                _only.parents( '.config-list' ).eq( 0 ).find( '.no-click' ).removeClass( 'no-click' );
                var isVisible = !_checkbox.get( 0 ).checked;

                //显示
                if( isVisible ){
                    _only.addClass( 'checked-li' );
                    _checkbox.get( 0 ).checked = true;
                    //_th.attr( 'th-visible','visible' );
                    //隐藏
                }else{
                    _only.removeClass( 'checked-li' )
                    _checkbox.get( 0 ).checked = false;
                    //_th.attr( 'th-visible','none' );
                }


                //最后一项禁止取消
                _checkedList =  $( '.config-area input[type="checkbox"]:checked');
                if( _checkedList.length == 1 ){
                    _checkedList.parent().addClass( 'no-click' );
                }


                //_this.setToLocalStorage( _table );	//缓存信息
            } );
        }

        /**
         * 初始化条件
         */
        this.initCondition = function() {
            //时间段选择
            $('.daterangepicker-sample1').daterangepicker({
                "startDate": self.param.filters.day.since,
                "endDate": self.param.filters.day.until,
                "opens": "nxdc",
                "alwaysShowCalendars": true,
                locale: {
                    "applyLabel": "OK",
                    "format": "YYYY-MM-DD",
                    "cancelLabel": ''
                },
                autoApply: true
            }, function (start, end, label) {
                self.param.filters.day.since = start.format('YYYY-MM-DD');
                self.param.filters.day.until = end.format('YYYY-MM-DD');
                self.param.groups.push("day");
            });

            var webSites = [];
            var acts = [];
            $.each(self.menus, function (index, item) {
                var it = {
                    name: item.webSite,
                    val: item.productManageProductId
                };
                webSites.push(it);
            });

            //站点选择
            $("div.ndp-drop-wrapper[name=drop-webSite]").empty().drop({
                data: webSites,
                name: "webSite",
                placeholder : I18N.getText("ecReport", "chooseWebSite")
            }).off("ITEM_CLICK").on("ITEM_CLICK", function (e) {
                self.param.filters.webSite = [];
                self.param.filters.account = [];
                self.param.filters.webSite.push(e.originalEvent.data.val);
                acts = _.where(self.menus, {productManageProductId: self.param.filters.webSite[0]})[0].fbAccounts;
                self.rendererDropActs(acts);
            });

            //渲染广告账号
            self.rendererDropActs(acts);

            //广告类型
            $("div.ndp-drop-wrapper[name=drop-adType]").empty().drop({
                data: [{id : "dpa", text : I18N.getText("ecReport", "dpa")},
                    {id : "other", text : I18N.getText("ecReport", "other")}],
                name: "adType",
                placeholder : I18N.getText("ecReport", "chooseAdType")
            }).off("ITEM_CLICK").on("ITEM_CLICK", function (e) {
                self.param.filters.adType = [];
                self.param.filters.adType.push(e.originalEvent.data.val);
                self.param.groups.push("adType");
            });

            //年龄段选择
            $("div.ndp-drop-wrapper[name=drop-age]").empty().drop({
                type: 4,
                data: [
                    {id : "all", text : I18N.getText("ecReport", "all")},
                    "13-17",
                    "18-24",
                    "25-34",
                    "35-44",
                    "45-54",
                    "55-64",
                    "65+",
                    {id : "unknown", text : I18N.getText("ecReport", "unknown")}],
                placeholder : I18N.getText("ecReport", "chooseAge")
            }).off("APPLY_CLICK").on("APPLY_CLICK", function (e) {
                if ($("#drop-age").hasClass("disabled")) {
                    self.alert(I18N.getText('ecReport','conflict', I18N.getText('ecReport','age'), I18N.getText('ecReport','device'), I18N.getText('ecReport','placement'), I18N.getText('ecReport','productId')));
                    $("#drop-age").find("input").val("");
                    return false;
                }
                var all = _.filter(e.originalEvent.data.checkedArr, function (i) {
                    return i.value == "all";
                })[0];
                self.param.filters.age = [];
                if (!all) {
                    $.each(e.originalEvent.data.checkedArr, function (index, item) {
                        if (!(item.value == "all")) {
                            self.param.filters.age.push(item.value);
                        }
                    });
                    self.param.groups.push("gender");
                } else {
                    self.param.groups = _.without(param.groups, "gender");
                }
                self.uiMutualExclusion();
            });

            //设备
            $("div.ndp-drop-wrapper[name=drop-device]").empty().drop({
                type: 4,
                data: [
                    {id : "all", text : I18N.getText("ecReport", "all")},
                    {id : "desktop", text : I18N.getText("ecReport", "desktop")},
                    {id : "mobile", text : I18N.getText("ecReport", "mobile")},
                    {id : "tablet", text : I18N.getText("ecReport", "tablet")},
                    {id : "other", text : I18N.getText("ecReport", "other")}
                ],
                placeholder : I18N.getText("ecReport", "chooseDevice")
            }).off("APPLY_CLICK").on("APPLY_CLICK", function (e) {
                if ($("#drop-device").hasClass("disabled")) {
                    self.alert(I18N.getText('ecReport','conflict', I18N.getText('ecReport','device'), I18N.getText('ecReport','age'), I18N.getText('ecReport','placement'), I18N.getText('ecReport','productId')));
                    $("#drop-device").find("input").val("");
                    return false;
                }
                var all = _.filter(e.originalEvent.data.checkedArr, function (i) {
                    return i.value == "all";
                })[0];
                self.param.filters.device = [];
                if (!all) {
                    $.each(e.originalEvent.data.checkedArr, function (index, item) {
                        self.param.filters.device.push(item.value);
                    })
                    self.param.groups.push("device");
                } else {
                    self.param.groups = _.without(self.param.groups, "device");
                }
                self.uiMutualExclusion();
            });
            //性别
            $("div.ndp-drop-wrapper[name=drop-gender]").empty().drop({
                type: 4,
                data: [
                    {id : "all", text : I18N.getText("ecReport", "all")},
                    {id : "male", text : I18N.getText("ecReport", "male")},
                    {id : "female", text : I18N.getText("ecReport", "female")},
                    {id : "unknown", text : I18N.getText("ecReport", "unknown")}
                ],
                placeholder : I18N.getText("ecReport", "chooseGender")
            }).off("APPLY_CLICK").on("APPLY_CLICK", function (e) {
                if ($("#drop-gender").hasClass("disabled")) {
                    self.alert(I18N.getText('ecReport','conflict', I18N.getText('ecReport','gender'), I18N.getText('ecReport','device'), I18N.getText('ecReport','placement'), I18N.getText('ecReport','productId')));
                    $("#drop-gender").find("input").val("");
                    return false;
                }
                var all = _.filter(e.originalEvent.data.checkedArr, function (i) {
                    return i.value == "all";
                })[0];
                self.param.filters.gender = [];
                if (!all) {
                    $.each(e.originalEvent.data.checkedArr, function (index, item) {
                        self.param.filters.gender.push(item.value);
                    })
                    self.param.groups.push("age");
                } else {
                    self.param.groups = _.without(self.param.groups, "age");
                }
                self.uiMutualExclusion();
            });

            //分组条件， 选项在html里
            $('#drop-group-select2').select2({
                placeholder: I18N.getText("ecReport", "chooseGroups")
            }).on('change', function () {
                self.param.groups = ["day"]; //默认值
                //处理界面
                if (!_.isEmpty(self.param.filters.account)) {
                    self.param.groups.push("account");
                }
                if (!_.isEmpty(self.param.filters.adType)) {
                    self.param.groups.push("adType");
                }
                if (!_.isEmpty(self.param.filters.age)) {
                    self.param.groups.push("age");
                }
                if (!_.isEmpty(self.param.filters.device)) {
                    self.param.groups.push("device");
                }
                if (!_.isEmpty(self.param.filters.gender)) {
                    self.param.groups.push("gender");
                }
                self.param.groups = _.union(self.param.groups, $(this).val());
                if (!self.isMutualExclusion(self.param.groups)) {
                } else {
                    self.param.groups = [];
                    $("#drop-group").find("input").val("");
                }
            });


        }

        /**
         * 渲染广告账号
         */
        this.rendererDropActs = function (acts) {
            //账号选择
            $("div.ndp-drop-wrapper[name=drop-acts]").empty().drop({
                type: 4,
                data: acts,
                name: "acts",
                placeholder : I18N.getText('ecReport','chooseAccounts')
            }).off("APPLY_CLICK").on("APPLY_CLICK", function (e) {
                self.param.filters.account = [];
                $.each(e.originalEvent.data.checkedArr, function (index, item) {
                    self.param.filters.account.push(item.value);
                })
                self.param.groups.push("account");
            });
        }

        /**
         * 界面互斥
         */
        this.uiMutualExclusion = function () {
            if (!_.isEmpty(param.filters.device)) {
                $("#drop-age").addClass("disabled");
                $("#drop-gender").addClass("disabled");
            } else {
                $("#drop-age").removeClass("disabled");
                $("#drop-gender").removeClass("disabled");
            }
            if (!_.isEmpty(param.filters.age || !_.isEmpty(param.filters.gender))) {
                $("#drop-device").addClass("disabled");
            } else {
                $("#drop-device").removeClass("disabled");
            }
        }

        /**
         * 检查互斥
         */
        this.isMutualExclusion = function(group) {
            if (_.contains(group, "device")) {
                if (_.contains(group, "age")) {
                    self.alert(I18N.getText('ecReport','conflictCheck', I18N.getText('ecReport','device'), I18N.getText('ecReport','age')));
                    return true;
                } else if (_.contains(group, "gender")) {
                    self.alert(I18N.getText('ecReport','conflictCheck', I18N.getText('ecReport','device'), I18N.getText('ecReport','gender')));
                    return true;
                }
            }
            if (_.contains(group, "placement")) {
                if (_.contains(group, "age")) {
                    self.alert(I18N.getText('ecReport','conflictCheck', I18N.getText('ecReport','placement'), I18N.getText('ecReport','age')));
                    return true;
                }
                if (_.contains(group, "gender")) {
                    self.alert(I18N.getText('ecReport','conflictCheck', I18N.getText('ecReport','placement'), I18N.getText('ecReport','gender')));
                    return true;
                }
            }
            if (_.contains(group, "productId")) {
                if (_.contains(group, "age")) {
                    self.alert(I18N.getText('ecReport','conflictCheck', I18N.getText('ecReport','productId'), I18N.getText('ecReport','age')));
                    return true;
                }
                if (_.contains(group, "gender")) {
                    self.alert(I18N.getText('ecReport','conflictCheck', I18N.getText('ecReport','productId'), I18N.getText('ecReport','gender')));
                    return true;
                }
                if (_.contains(group, "device")) {
                    self.alert(I18N.getText('ecReport','conflictCheck', I18N.getText('ecReport','productId'), I18N.getText('ecReport','device')));
                    return true;
                }
                if (_.contains(group, "placement")) {
                    self.alert(I18N.getText('ecReport','conflictCheck', I18N.getText('ecReport','productId'), I18N.getText('ecReport','placement')));
                    return true;
                }
            }
        }

        this.alert = function (c, t) {
            if (!t) {
                t = "TIPS";
            }
            showAlert({title: t, content: c});
        }

        /**
         * 初始化表格
         */
        this.initTable = function(data) {
            var headArr = []
            var dataArr = [];
            var summary = [];
            _.map(data.list, function (item) {
                var each = [];
                each.push({text: item.day});
                each.push({text: moment(item.day).format("dddd")});
                each.push({text: (item.spend / 100).toFixed(2) + "$"});
                each.push({text: item.fbData.impressions});
                each.push({text: item.fbData.clicks});
                each.push({text: (item.fbData.cpc / 100).toFixed(2) + "$"});
                each.push({text: item.fbData.cart});
                each.push({text: item.fbData.checkout});
                each.push({text: (item.fbData.checkoutCR * 100).toFixed(2) + "%"});
                if (item.fbData.checkout == 0) {
                    each.push({text: "-"});
                } else {
                    each.push({text: (item.fbData.cps / 100).toFixed(2) + "$"});
                }
                each.push({text: (item.fbData.salesAmount / 100).toFixed(2) + "$"});
                each.push({text: (item.fbData.roi).toFixed(2)});

                each.push({text: item.gaData.clicks});
                each.push({text: (item.gaData.cpc / 100).toFixed(2)});
                each.push({text: item.gaData.cart});
                each.push({text: (item.gaData.cartCR * 100).toFixed(2) + "%"});
                each.push({text: item.gaData.pays});
                each.push({text: (item.gaData.cr * 100).toFixed(2) + "%"});
                each.push({text: (item.gaData.cpa / 100).toFixed(2) + "$"});
                each.push({text: (item.gaData.orderAmount / 100).toFixed(2) + "$"});
                each.push({text: (item.gaData.orderPrice / 100).toFixed(2) + "$"});
                each.push({text: (item.gaData.roi).toFixed(2)});


                dataArr.push({label:each});
            });

            _.each(self.tableTh, function(li){
                if(li.isShow)
                    headArr.push({label: I18N.getText('ecReport',li.label)});
            });

            _.each(data.fbSummary, function(m, n){
                summary.push({text:m});
            });
            //var data1=[{label:[{name:"中华人民共和国"},{text:"运行中"},{text:"9000"},{text:"10-1"},{text:"2000-1"},{text:"1100"},{text:"4000"},{text:"987"},{text:"601"},{text:"107"},{text:"222"},{text:1100}]},{label:[{name:"美国"},{text:"审核未通过"},{text:2},{text:20},{text:2e3},{text:2},{text:20},{text:2},{text:20},{text:100},{text:200},{text:1100}]},{label:[{name:"美国"},{text:"运行中"},{text:2},{text:20},{text:2e3},{text:2},{text:20},{text:2},{text:20},{text:100},{text:200},{text:1100}]}];
            var hwd = $(".ndp-sutable-wrapper").empty().sutable({
                head:headArr,
                body:dataArr,
                //列表 最下面 总计数据
                tail:summary,
                sort:[3]// 第4列，6列，8页  10页显示 排序按钮  默认从0开始
            }).on("SORT_CLICK",function(e){//用户点击排序按钮
                //返回数据，包含，第几列，默认0； 列名
                console.log(e.originalEvent.data);//{col: 3, val: "点击数"}
            });


//            $("#update").click(function(){
//                bool = !bool;
//                hwd.update((bool?data2:data1),sum);
//            });
//
////更新ajax 请求的参数
//            $("#ajax").click(function(){
//                hwd.updateAjaxOption({
//                    url: "../data/sutable2.json"
//                });
//            });

        }


        /**
         * 初始化模板详情页头部
         */
        self.initDetailHeadHtml = function() {
            self.$root.find('.template-detail-head-img img').attr('src', self.templateImg);
            self.$root.find('.template-detail-head-name').text(self.templateName);
            self.$root.find('.template-detail-head-category').text(window.localStorage.getItem('goDetailTemplateCategory'));
        }

        /**
         * { 上传模板modal }
         *
         * @method     openUploadDialog
         */
        this.openUploadDialog = function() {
            //new UploadDialogView().init(function() {
            //    self.getTemplateList();
            //});
        }



    }
    return new me();
});
